package test;
import std::IO;
import std::Type;

public class TestControlStatement{
	public static test(){
		//空语句；
		;
		//简单语句；
		TestControlStatement.testsingle();
		
		//复合语句；
		TestControlStatement.testcomplex();
		
		//if/else语句；
		TestControlStatement.testifelse();

		//while/do语句；
		TestControlStatement.testwhiledo();
		
		//break/continue语句；
		TestControlStatement.testbreakcontinue();
		//try/catch语句；
		try{
			IO.printf("测试异常捕获\n");
			//throw语句；
			TestControlStatement.testthrow();
		}catch(e->Type){
			IO.printf("捕获异常:%d\n", e);
		}

		//return语句；
		TestControlStatement.testreturn();
	}

	static testsingle(){
		IO.printf("测试简单语句\n");
		a0->boolean = true;
		a1->byte = 0;
		a2->char = '1';
		a3->short = 2;
		a4->int = 3;
		a5->long = 4;
		a6->float = 5;
		a7->double = 6;
		IO.printf("%z %b %c %S %d %D %f %F\n", 
			Type.get(a0),
			Type.get(a1),
			Type.get(a2),
			Type.get(a3),
			Type.get(a4),
			Type.get(a5),
			Type.get(a6),
			Type.get(a7)
		);
	}

	static testcomplex(){
		IO.printf("测试复合语句\n");
		a0->int = 0;
		{
			a0->int = 1;
			a1->int = 2;
			IO.printf("%d %d ", Type.get(a0), Type.get(a1));
		}
		{
			a1->int = 4;
			IO.printf("%d %d\n", Type.get(a0), Type.get(a1));
		}
	}

	static testifelse(){
		IO.printf("测试if/else语句\n");
		a0->int = 3;
		if(a0<5) IO.printf("%d<5 ", Type.get(a0));
		else IO.printf("5<=%d ", Type.get(a0));
		a0 = 7;
		if(a0<5) IO.printf("%d<5 ", Type.get(a0));
		else IO.printf("5<=%d ", Type.get(a0));
		IO.printf("\n");
	}

	static testwhiledo(){
		IO.printf("测试循环语句\n");
		a0->int = 0;
		while(a0<10) 
			IO.printf("%d ", Type.get(a0++));

		a0 = 0;
		do 
			IO.printf("%d ", Type.get(a0++));
		while(a0<10);
		IO.printf("\n");
	}

	static testbreakcontinue(){
		IO.printf("测试中断语句\n");
		a0->int = 0;
		while(a0<10) {
			IO.printf("%d ", Type.get(a0++));
			if(a0==5)break;
			else continue;
			IO.printf("测试中断语句出错\n");
		}
		IO.printf("\n");
	}

	static testthrow(){
		IO.printf("测试抛出异常\n");
		throw Type.get(2);
		IO.printf("测试抛出异常出错\n");
	}

	static testreturn(){
		IO.printf("测试return语句\n");
		return;
		//IO.printf("测试return语句出错\n");
	}
}